package com.zb.controller;


import com.zb.entity.dto.LogisticsDto;
import com.zb.entity.dto.LogisticsSelectDto;
import com.zb.exception.RegisterException;
import com.zb.result.Result;
import com.zb.service.ZjAdmLogisticsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 后台物流表 前端控制器
 * </p>
 *
 * @author WEN
 * @since 2023-07-11
 */
@Api(tags = "物流类接口")
@RestController
@RequestMapping("/logistics")
public class ZjAdmLogisticsController {
    @Autowired
    private ZjAdmLogisticsService admLogisticsService;

    @ApiOperation("添加或修改物流")
    @PostMapping("/save")
    public Result save(@RequestBody @Valid LogisticsDto logisticsDto) throws RegisterException {
        admLogisticsService.save(logisticsDto);
        return Result.success(null == logisticsDto.getId()? "添加物流成功" : "修改物流成功");
    }

    @ApiOperation("物流列表")
    @PostMapping("/getList")
    public Result getList(@RequestBody @Valid LogisticsSelectDto selectDto) {
        return Result.success("获取物流列表成功").data(admLogisticsService.getList(selectDto));
    }

    @ApiOperation("批量启用或禁用物流")
    @PutMapping("/disble")
    public Result disable(@RequestParam @ApiParam("禁用：false-否，true-是") boolean disable,
                          @RequestBody @ApiParam("物流ID集合") List<Long> idList) {
        admLogisticsService.batchDisableById(idList, disable);
        return Result.success(disable? "禁用物流成功" : "启用物流成功");
    }

    @ApiOperation("删除物流")
    @DeleteMapping("/{id}")
    public Result remove(@PathVariable Long id) {
        admLogisticsService.removeById(id);
        return Result.success("删除物流成功");
    }


}
